;(function(){
	//父类
	var Animal = function(){
		this.name = name;
		//	实例方法
		this.sleep = function(){
			console.log(this.name+'正在睡觉！');
		}
		
	}
	var Person = function(){
		this.walk = function(){
			console.log(this.name+'用脚走');
		}
	}
	
	
	Animal.prototype.eat = function(food){
		console.log(this.name+'正在吃'+food);
	}
	
	
	//原型链继承 
	var Cat = function(){
		
	}
	//父类的实例作为子类的原型
	Cat.prototype = new Animal();
	//修改属性
	Cat.prototype.name = 'cat';
	
	var cat = new Cat();
	cat.name;
	cat.sleep();	
	cat.eat('fish');
	console.log(cat instanceof Animal);
	console.log(cat instanceof Cat);

	
	//构造继承 直接在子类call父类，就把父类里的属性方法给子类
	var Pig = function(){
		
		Animal.call(this);
		Person.call(this);
		this.name = 'tom';
	}
	var pig = new Pig();
	pig.sleep();
	pig.walk();
	console.log(pig instanceof Animal);
	console.log(pig instanceof Pig);
	
	//实例继承 
	var Dog = function(){
		// 在子类里new 父类的实例返回子类
		var instance = new Animal();
		instance.name = 'json';
		
		return instance;
	}
	var dog = new Dog();
	dog.sleep();
	console.log(dog instanceof Animal);
	console.log(dog instanceof Dog);
	//拷贝继承
	var Duck = function(){
		// 把父类里的方法看成数组，将数组的值一个一个传入子类 也就是把方法传给子类
		
		var animal = new Animal();
		for(p in animal){
			Duck.prototype[p] = animal[p];
		}
		Duck.prototype.name = 'tang';
	}
	
	var duck = new Duck();
	duck.sleep();
	console.log(duck instanceof Animal);
	console.log(duck instanceof Duck);
	
	
	//组合继承
	
	var Snake = function(){
		// 还是像构造继承一样 先把父类的方法给子类 
		Animal.call(this);
		Person.call(this);
		this.name = 'xiaobao';
	}
	//然后把父类的实例给子类的原型
	Snake.prototype = new Animal();
	var snake = new Snake();
	snake.sleep();
	snake.walk();
	console.log(snake instanceof Animal);
	console.log(snake instanceof Snake);
	
	//寄生组合继承
	var Mouse = function(){
		Animal.call(this);
		this.name = 'chen';
	}
	// 创建一个空的类 
	var Super = function(){}
	// 将父类的原型给空类
	Super.prototype = Animal.prototype;
	
	//将空的类的实例给子类的原型
	Mouse.prototype = new Super();
	
	var mouse = new Mouse();
	mouse.sleep();
	console.log(mouse instanceof Animal);
	console.log(mouse instanceof Mouse);
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
})();